package com.zymail.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BaseController {
    @Autowired
    StringRedisTemplate redisTemplate;

    /**
     * session_key -> userId
     * @param session_key session_key
     * @return  userid
     */
    protected Integer get_userId(String session_key){
        ValueOperations<String, String> operations = redisTemplate.opsForValue();
        String userId = operations.get(session_key);
        if(userId == null){return 0;}
        return Integer.parseInt(userId);
    }
}
